import { TimeDate } from '@/utils/index';
import { useState, useEffect, useMemo } from 'react';

const useTimer = () => {
  const [timer, set_timer] = useState(0);

  useEffect(() => {
    set_timer(new Date().getTime());

    const djq = setInterval(() => {
      set_timer(new Date().getTime());
    }, 1000);

    return () => {
      clearInterval(djq);
    };
  }, []);

  const time = useMemo(() => {
    return TimeDate(timer);
  }, [timer]);

  return time;
};

export default useTimer;
